<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.tss.util.*"%>
<%@page import="com.jedi.*"%>
<%@page import="java.util.*"%>
<%@include file="../global_var.jsp"%>
<%@include file="../check_login.jsp"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

User user = (User)session.getAttribute("LoginUser");
MessageMgr msgMgr = new MessageMgr();
String cmd = ParamUtils.getParameter(request,"cmd","");
String id = ParamUtils.getParameter(request,"id","");

String strErr = "";
Message msg = msgMgr.get(id);
if (msg == null || msg.getId().trim().equals("")) strErr = "要回复的咨询信息不存在!";
if (msg != null && msg.getMsgType() != 0) strErr = "此信息为回复信息，不能再被回复!";

String msg_title   = ParamUtils.getParameter(request,"msg_title","");
String msg_info    = ParamUtils.getParameter(request,"msg_info","");

if (msg_title.trim().equals("") && strErr.trim().equals("")) msg_title =  msg.getMsgTitle();

String author_id   = "";
String author_name = "";

if (user != null && !user.getId().trim().equals("")) {
	author_id = user.getId();
	author_name = user.getUserName();
}

if (cmd.trim().equals("insert") && strErr.trim().equals("")) {
	if (strErr.trim().equals("") && msg_title.trim().equals("")) {
		strErr = "主题不能为空!";
	}
	if (strErr.trim().equals("") && msg_info.trim().equals("")) {
		strErr = "内容不能为空!";
	}
	if (strErr.trim().equals("") && msg_info.length() > 150) {
		strErr = "内容不能超过150个字符!";
	}

	if (strErr.trim().equals("")) {
		Message msgItem = new Message();
		msgItem.setAuthorId(author_id);
		msgItem.setAuthorName(author_name);
		msgItem.setMsgType(1);
		msgItem.setMsgTitle(msg_title);
		msgItem.setMsgInfo(msg_info);
		msgItem.setIssueTime(TSSDate.fullTime());
		msgItem.setReplyId(id);
		msgItem.insert();
		if (msgItem.hasErr()) strErr = msgItem.getErrHtml();
	}
}
%>
<html>
<head>
 <base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
<link href="style/main.css" rel="stylesheet" type="text/css">
<script language="javascript" src="js/common.js"></script>
<script language="javascript">
function chk_submit() {
	var oForm = document.operatorForm;
	if (oForm.msg_title.value == "") {
		alert("主题不能为空");
		oForm.msg_title.focus();
		return false;
	}
	if (oForm.msg_info.value == "") {
		alert("内容不能为空");
		oForm.msg_info.focus();
		return false;
	}
	oForm.cmd.value = "insert";
	return true;
}
</script>
</head>
<body  leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td >
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
       
        <tr> 
          <td height="100" align="center" valign="top" style="padding-top:20px;padding-bottom:10px;">
           <form name="operatorForm" method="post" onsubmit="return chk_submit();">
            <table width="80%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
             
              <%if (!strErr.trim().equals("")) {%>
              <tr> 
                <td width="30%" height="28" align="right" bgcolor="#858585"><font color="#FFFFFF">错误提示：</font></td>
                <td bgcolor="#EDEDF0"><font color=red><%=strErr%></font>&nbsp;</td>
              </tr>
              <%}%>
              <tr> 
                <td width="30%" height="24" align="right" bgcolor="#858585"><font color="#FFFFFF">主　题：</font></td>
                <td bgcolor="#D7D7DB"><input name="msg_title" type="text" class="inputbox" value="<%=msg_title%>" size="30"  style="background-color:#EDEDE8" readonly="readonly"></td>
              </tr>
              <tr>
                <td height="24" align="right" bgcolor="#858585"><font color="#FFFFFF">内　容：</font></td>
                <td bgcolor="#EDEDF0">
                  <textarea name="msg_info" cols="40" rows="5"><%=msg_info%></textarea>
                </td>
              </tr>
              <tr> 
                <td height="24" align="right" bgcolor="#EDEDF0">&nbsp;</td>
                <td bgcolor="#EDEDF0"> 
                  <input type="submit" name="submit" value="提 交" class="inputButton"> 
                  <input type="reset" name="reset" value="重 写" class="inputButton"> 
                  <input type="hidden" name="cmd" value=""> 
                </td>
              </tr>
         
            </table>
                 </form>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<%if (cmd.equals("insert") && strErr.trim().equals("")){%>
<script language="javascript">
alert("咨询信息添加成功!");
location.href = "knowledge_msg_list.jsp";
</script>
<%}%>
</body>
</html>